import wsgiref.handlers
from google.appengine.ext import webapp

import EventRecord

class Event( webapp.RequestHandler ):

  def get( self ):
    self.response.headers['Content-Type'] = 'text/html'

    id = self.request.get('id')
    record = EventRecord.EventRecord \
      .gql( 'WHERE id = :1', id ) \
      .get()

    if not record:
      self.response.out.write( 'Invalid event id.' )
      return

    filling =  {
        'title' : record.title
      , 'date' : record.date
      , 'time' : record.time
      , 'venue' : record.venue
      , 'id' : record.id
    }

    self.response.out.write(
'''
<h3>Event Registration</h3>
<p>
  Title - %(title)s<br />
  Date - %(date)s<br />
  Time - %(time)s<br />
  Venue - %(venue)s<br />
</p>
<form action="register_event" method="post" accept-charset="utf-8">
  <fieldset>
    <legend>Register Event</legend>
    <table>
    <tr><td>Your Name:</td><td><input type="text" name="name" id="name" /></td></tr>
    <tr><td>Your Email:</td><td><input type="text" name="email" id="email" /></td></tr>
    <tr><td colspan="2"><button type="submit">Register!</button></td></tr>
    </table>
  </fieldset>
  <input type="hidden" name="id" id="id" value="%(id)s" />
</form>
<a href="http://appengine.google.com/" target="_blank"><img
src="http://code.google.com/appengine/images/appengine-silver-120x30.gif"
alt="Powered by Google App Engine" style="border:none;" /></a>
''' % filling )
  # end of Event.get

# end of class Event
